<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<include file="Public:meta" />
    <style>
    	.IsDefault{ background:#333;color:#fff; padding:0; display:none; margin:0 3px;}
		#c{$DefaultConsigneeID} { display:block;}
		#b{$DefaultConsigneeID} { display:none;}
    </style>
</head>
<body id="main_page">
<include file="Public:position" />
<div class="container">
    <form enctype="multipart/form-data" method="post" id="frm">
          <div class="table">          
            <div class="toolbars">
                <li class="toolbar"><a id="btnSaveAll" href="{$Url}Add"  title="添加收货地址" target="_self">添加收货地址</a></li>
                <li class="toolbar"><a id="selectall" onclick="CheckAll()"  title="全选">全选</a></li>
                <li class="toolbar"><a id="del" onclick="batchDel()" title="批量删除">删除</a></li>
            </div>
            <table class="datatable" id="datatable">
            <tr>
                <th width="45px">选中</th>
                <th width="80px">地址别名</th>
                <th width="80px">姓名</th>
                <th width="220px" >联系方式</th>
                <th>地址</th>
                
                <th  width="70px">邮政编码</th>
                <th  width="60px">是否默认</th>
                <th width="268px">操作</th>
            </tr>  
            <notempty name="Data">
                <volist name="Data" id="d">
                    <tr>
                        <td><input class="checkrow" type="checkbox" name="id[]" value="{$d.ConsigneeID}" /></td>
                        <td>{$d.ConsigneeAddressAlias}</td>
                        <td>{$d.ConsigneeRealName}</td>
                        <td style="text-align:left; padding-left:5px;">
                            手机：{$d.ConsigneeMobile}<br/>
                            座机：{$d.ConsigneeTelephone}<br/>
                            Email：{$d.ConsigneeEmail}
                        </td>
                        <td style="text-align:left; padding-left:5px;">{$d.ConsigneeAddress}</td>
                        
                        <td>{$d.ConsigneePostcode}</td>
                        <td><div id="c{$d.ConsigneeID}" class="IsDefault">默认地址</div></td>
                        <td class="operator">
                            <a style="float:left" href="{$Url}Modify/id/{$d.ConsigneeID}" id="btnEdit">修改</a>
                            <div class="btn-sep"></div>
                            <a style="float:left;" onclick="del({$d.ConsigneeID})" class="btnDel">删除</a>
                            <div class="btn-sep"></div>
                            <div style="float:left; "  id="b{$d.ConsigneeID}" class="ShowButton">
                                <a id="btnSaveAll" name="btnSaveAll" onclick="setDefault({$d.ConsigneeID})">设为默认地址</a>
                            </div>
                        </td>
                    </tr>
                </volist> 
            <else/>
                <tr><td colspan="9"  id="NoData">{$Think.lang.NoDataTip}</td></tr>
            </notempty>                                
    </table>
            <div class="tfoot"></div>
         </div>
    </form>
</div>
</body>
</html>
<script type="text/javascript">
function del(id){
	$.confirm("{$Think.lang.DeleteTip}", function () {
		url = "{$Url}del/id/"+id;
		location.href = url;
	}, function () {
		return true;
	});
}

function batchDel(){
	var arrChk = $("input[name='id[]']");
	var n = 0;
	for(var i = 0; i < arrChk.length; i++){
		if(arrChk[i].checked) n++;
	}
	
	if( n == 0 ) {
		WarnBox("{$Think.lang.CheckDeleteTip}");
		return;
	}
	
	$.confirm("{$Think.lang.DeleteTip}", function () {
		$('#frm').attr("action", "__URL__/del");
		$('#frm').submit();
	}, function () {
		return true;
	});
}

//设置为默认地址
function setDefault(id){
	var url = "{$Url}setDefault/id/"+id;
	LoadBox();
	$.get(url, null, function(data){
		CloseLoadBox();
		//默认提示
		$(".datatable .IsDefault").hide();
		$("#c"+id).show();	
		
		//按钮
		$(".datatable .ShowButton").show();
		$("#b"+id).hide();	
	}, "json");
}
</script>